/*
 * @Author: your name
 * @Date: 2022-02-27 23:35:11
 * @LastEditTime: 2022-02-28 23:11:01
 * @LastEditors: your name
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \the-way-of-interview\instanceof.js
 */
function myInstanceof(left, right) {
    left = left.__proto__
    let prototype = right.prototype
    while (true) {
        if (left === null || left === undefined)
            return false
        if (prototype === left)
            return true
        left = left.__proto__
    }
}

function Car(make, model, year) {
    this.make = make;
    this.model = model;
    this.year = year;
}

var auto = new Car('Honda', 'Accord', 1998);

console.log(myInstanceof(auto, Car));
// expected output: true

console.log(myInstanceof(auto, Object));
// expected output: true

function myInstanceof1(left, right) {
    left = left.__proto__
    let prototype = right.prototype
    while(true) {
        if(left === null || left === undefined){
            return false
        }
        if(prototype === left){
            return true
        }
        left = left.__proto__
    }
}